<?php
require_once"./libraries/utilites/functions.php";
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$fimls = mreadFile($full_path);
?>
<form method="POST" >
    <input type="text" name="rating" placeholder="rating 1">
    <input type="text" name="rating1" placeholder="rating 2">
    <input type="submit" name="submit" value="Search">
</form>
<?php
$loi = false;
for ($i = 0; $i < count($fimls); $i++):
    $b = trim($fimls[$i], "\t\n\r ");
    $mang = explode(";", $b); // token ra va cho vao $mang;
    if ($b != "") {
        if (isset($_POST["rating"])) {
            if (is_numeric($_POST["rating"])&&is_numeric($_POST["rating1"])) {
                if ($mang[2] >= (double) $_POST["rating"]&&$mang[2] <=(double) $_POST["rating1"]) {
                    ?>
                    <img src="../ptnhuan-web1/public/images/films/<?php if (!empty($mang[0])) echo $mang[0]; ?>"/>
                    <?php if (!empty($mang[1])) echo $mang[1]; ?>
                    <?php if (!empty($mang[2])) echo $mang[2]; ?>
                    <BR>
                    <?php
                }   
            }
            else
                $loi = 2;
        }
        else {
            ?> 
            <img src="../ptnhuan-web1/public/images/films/<?php if (!empty($mang[0])) echo $mang[0]; ?>"/>
            <?php if (!empty($mang[1])) echo $mang[1]; ?>
            <?php if (!empty($mang[2])) echo $mang[2]; ?>
            <BR>
            <?php
        }
    }
endfor;
    if($loi==true)
    echo "Bạn nhập không phải là số hoặc chưa nhập giá trị";
?>

